package primary.dynamic_programming;

/**
 * @Author Elephas
 * @Date 2022/1/8
 **/
public class ClimbStairs {
    public int climbStairs(int n){
        int[] dp = new int[3];
        dp[0] = 1; dp[1] = 2;
        if(n == 1){
            return dp[0];
        }else if( n == 2){
            return dp[1];
        }else{
            for (int i = 2; i < n; i++) {
                dp[2] = dp[0]+dp[1];
                dp[0] = dp[1];
                dp[1] = dp[2];
            }
            return dp[2];
        }
    }
}
